package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.MenuDao;
import pe.edu.upc.dew.sisrest.model.Menu;

@Repository
public class MenuDaoHibernate extends HibernateDaoSupport implements MenuDao {
    
    @Autowired
    public MenuDaoHibernate(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
    }    
    @Override
    public List<Menu> obtenerListaMenus() {
        List list = getHibernateTemplate().find(" from Menu ");
        return list;
    }

    @Override
    public Menu obtenerMenuById(String idMenu) {
        Menu menu = getHibernateTemplate().get(Menu.class, idMenu);
	return menu;
    }

    @Override
    public void guardarMenu(Menu menu) {
      getHibernateTemplate().saveOrUpdate(menu);
    }

    @Override
    public void actualizarMenu(Menu menu) {
        guardarMenu(menu);
    }

    @Override
    public void eliminarMenu(String idMenu) {
        Menu menu = obtenerMenuById(idMenu);
        getHibernateTemplate().delete(menu);
    }

}
